package durose.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import durose.system.dict.CommonDict;

import durose.system.pojo.Sys_log; 
import durose.system.service.Sys_logService;
 import durose.system.springUtil.SpringSys_logFactory; 

 import com.github.pagehelper.Page;
import durose.system.dict.ResponseDict;

@Controller
public class Sys_logController {
	String prefix = "system/durose/sys_log/";
	
	
	
	@Autowired
	Sys_logService sys_logService;
	
	
	@RequestMapping("sys_log")
	public String sys_logGet(){
		return prefix+"sys_log";
	}
	
	@RequestMapping("sys_log_list")
	@ResponseBody
	public Object sys_logList(@RequestParam(value="pageNumber",defaultValue="0")Integer pagenumber,@RequestParam(value="queryName",required=false) String queryName){
		PageHelper.startPage(pagenumber,CommonDict.PAGE_SIZE);
		
		
	List<Sys_log> sys_loges = sys_logService.sys_logList(queryName);
		//把从数据库中查询的pojo数据与所关联的表进行处理
		List<Map<String,Object>> mapList = SpringSys_logFactory.me().initData((Page)sys_loges);
		PageInfo<Map<String,Object>> page = new PageInfo<>(mapList);
		return page;
	}
	
	@RequestMapping("sys_log_add")
	@ResponseBody
	public Object sys_logAdd(Sys_log pojo){
		sys_logService.sys_logAdd(pojo);
		return new ResponseDict(CommonDict.BUS_STATUS_OK);
	}
	
	@RequestMapping("sys_log_add_page")
	public String sys_logAddPage(Model model){
		
		return prefix+"sys_log_add";
	}
	
	@RequestMapping("sys_log_edit")
	@ResponseBody
	public Object sys_logEdit(Sys_log pojo){
		sys_logService.sys_logUpdate(pojo);
		return new ResponseDict(CommonDict.BUS_STATUS_OK);
	}
	
	@RequestMapping("sys_log_edit_page")
	public String  sys_logEditPage(int id,Model model){
		
		model.addAttribute("sys_log", sys_logService.sys_logGet(id));
		return prefix+"sys_log_edit";
	}
	
	@RequestMapping("sys_log_delete")
	@ResponseBody
	public Object sys_logDelete(int id){
		sys_logService.sys_logDelete(id);
		return new ResponseDict(CommonDict.BUS_STATUS_OK);
	}
	
	
}
